package cc.higou.core.controller;

import cc.higou.core.pojo.Order;
import cc.higou.core.tools.SessionTool;
import cc.higou.service.Orderservice;
import cc.higou.service.SessionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 说明：
 * 订单的控制器
 *
 * @author:dongxing
 * @time:--
 */

public class OrderController {

    @Autowired
    private SessionService sessionService;

    @Autowired
    private Orderservice orderservice;


    @RequestMapping(value = "/buyer/submitOrder")
    public String submitOrder(Order order, Model model, HttpServletRequest request, HttpServletResponse response) {
        //获取登录的用户名
        String xingsessid = SessionTool.getSession(request, response);
        String username = sessionService.getUserFromRedis(xingsessid);

        try {
            orderservice.addOrderAndDetail(order, username);
            return "success";
        } catch (IOException e) {
            e.printStackTrace();
        }
        return "success";
    }
}
